<?php

namespace app\admin\controller;

use think\Controller;
use think\Db;

class Systems extends Controller
{

    //系统配置读取
    public function deploy(){
        $data = [
            'data' => '',
            'success' => false,
            'messages' => '读取失败'
        ];
        $system = model('System')->where('id',1)->find();
        if ($system){
            $system['address'] = json_decode(  $system['address']);
            $data['success'] = true;
            $data['messages'] = '读取成功';
        }
        $data['data'] = $system;
        return json($data);

    }
    //修改
    public function updateSystems(){
        $return = [
            'success' => false,
            'messages' => '更新失败'
        ];

            $data = [
                'name'=>input('put.name'),
                'desc'=>input('put.desc'),
                'photo'=>input('put.photo'),
                'phone'=>input('put.phone'),
                'email'=>input('put.email'),
                'address'=>json_encode(input('put.address')),
                'icpNum'=>input('put.icpNum'),
                'icpHref'=>input('put.icpHref'),
                'href'=>input('put.href'),
                'update_time' =>time()
            ];

                $result = Db::table('system')->where('id',1)->update($data);
                if ($result){
                    $return['success'] = true;
                    $return['messages'] = '更改成功';
                }else{
                    $return['messages'] = $result;
                }


        return json($return);

    }
}
